class Solution {
public:
    bool isZeroArray(vector<int>& nums, vector<vector<int>>& queries) {
        vector<int> arr(nums.size() + 5);
        for (int i = 0, pre = 0; i < nums.size(); i++) {
            arr[i] = nums[i] - pre;
            pre = nums[i];
        }
        for (int i = 0; i < queries.size(); i++) {
            int l = queries[i][0], r = queries[i][1];
            arr[l] -= 1;
            arr[r + 1] += 1;
        }
        int sum = 0;
        for (int i = 0; i < nums.size(); i++) {
            sum += arr[i];
            if (sum > 0) return false;
        }
        return true;
    }
};
